package com.tuanzi.loan.web.bean.system.log;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;

import com.tuanzi.loan.log.vo.request.ErrorLogSearchRequest;
import com.tuanzi.loan.log.vo.response.ErrorLogDetailResponse;
import com.tuanzi.loan.log.vo.response.ErrorLogSearchResponse;
import com.tuanzi.loan.web.lazy.system.log.error.ErrorLogLazyDataModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.tuanzi.loan.log.service.ErrorLogService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.web.configuration.JSFListingBean;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
 * @author JinRuiyang 2017/11/27
 */
@Data
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class ErrorLogListBean extends JSFListingBean<ErrorLogSearchRequest, ErrorLogSearchResponse> {

	private static final long serialVersionUID = -2152778554108785347L;

	private List<String> projectNames;

	@Autowired
	private ErrorLogService errorLogService;

	@PostConstruct
	private void init() {
	    this.projectNames = errorLogService.getAllProjectName();
		initLazyDataModel();
	}

	public void onReset() {
		initLazyDataModel();
	}

	public void onRefresh(){
        lazyDataModel = new ErrorLogLazyDataModel($);
        addSuccessfullyMessage();
    }

	public void getDetail(Long currentChooseLogId) {
		$.setCurrentErrorLogDetail(errorLogService.findById(currentChooseLogId));
	}

	public void onChecked(ErrorLogSearchResponse response) {
        errorLogService.setDone(response);
        addSuccessfullyMessage();
	}

	private void initLazyDataModel() {
		$ = new ErrorLogSearchRequest();
		lazyDataModel = new ErrorLogLazyDataModel($);
    }
}
